Иногда нужно выполнить блок кода с несколькими менеджерами контекста:
with open('f') as f: with open('g') as g: with open('h') as h: pass
Начиная с Python 2.7 и 3.1, это можно записать в одной конструкции with:
o = open with o('f') as f, o('g') as g, o('h') as h: pass
Раньше для этого использовали функцию contextlib.nested:
with nested(o('f'), o('g'), o('h')) as (f, g, h): pass
Если же число менеджеров контекста заранее неизвестно, лучше подойдёт более продвинутый инструмент. contextlib.ExitStack позволяет открывать любое число контекстов в произвольный момент, но гарантирует корректный выход из них в конце:
with ExitStack() as stack: f = stack.enter_context(o('f')) g = stack.enter_context(o('g')) other = [ stack.enter_context(o(filename)) for filename in filenames ]
Иногда нужно выполнить блок кода с несколькими менеджерами контекста:
with open('f') as f: with open('g') as g: with open('h') as h: pass
Начиная с Python 2.7 и 3.1, это можно записать в одной конструкции with:
o = open with o('f') as f, o('g') as g, o('h') as h: pass
Раньше для этого использовали функцию contextlib.nested:
with nested(o('f'), o('g'), o('h')) as (f, g, h): pass
Если же число менеджеров контекста заранее неизвестно, лучше подойдёт более продвинутый инструмент. contextlib.ExitStack позволяет открывать любое число контекстов в произвольный момент, но гарантирует корректный выход из них в конце:
with ExitStack() as stack: f = stack.enter_context(o('f')) g = stack.enter_context(o('g')) other = [ stack.enter_context(o(filename)) for filename in filenames ]
Bitcoin mining is the process of adding new transactions to the Bitcoin blockchain. It’s a tough job. People who choose to mine Bitcoin use a process called proof of work, deploying computers in a race to solve mathematical puzzles that verify transactions.To entice miners to keep racing to solve the puzzles and support the overall system, the Bitcoin code rewards miners with new Bitcoins. “This is how new coins are created” and new transactions are added to the blockchain, says Okoro.
The lead from Wall Street offers little clarity as the major averages opened lower on Friday and then bounced back and forth across the unchanged line, finally finishing mixed and little changed.The Dow added 33.18 points or 0.10 percent to finish at 34,798.00, while the NASDAQ eased 4.54 points or 0.03 percent to close at 15,047.70 and the S&P 500 rose 6.50 points or 0.15 percent to end at 4,455.48. For the week, the Dow rose 0.6 percent, the NASDAQ added 0.1 percent and the S&P gained 0.5 percent.The lackluster performance on Wall Street came on uncertainty about the outlook for the markets following recent volatility.